package com.yanqu.road.server.logic.bag;

import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.player.UserVehicleSoul;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleSoulModule;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.string.StringUtils;

/**
 * 使用后添加魂石
 */
public class UseAddVehicleSoul extends BaseUseGoods {

	public UseAddVehicleSoul(GamePlayer player, GoodsInfo goodsInfo, long param) {
		super(player, goodsInfo, param);
	}

	@Override
	int checkUse(long count) {
		// 检测是否在有效期
		if(!player.getModule(VehicleSoulModule.class).canMakeOne(count)){
			return GameErrorCode.E_VEHICLE_SOUL_NUM_MAX;
		}
		return 0;
	}

	@Override
	UseGoodsResult executeUse(long count) {
		UseGoodsResult result = new UseGoodsResult();
		String reward = "";
		for(int i = 0;i < count;i++){
			UserVehicleSoul userVehicleSoul = player.getModule(VehicleSoulModule.class).makeOneSoul(goodsInfo,0,true);
			if(userVehicleSoul != null){
				if(!StringUtils.isNullOrEmpty(reward)){
					reward += "|";
				}
				reward += userVehicleSoul.getConfigId() + ";" + StringUtils.listToString(userVehicleSoul.getOccList(),";");
			}
		}
		result.setReward(reward);
		return result;
	}
}
